jQuery(document).ready(function($) {
 
// $(window).load(function() {	

//	$('.player-container').css('visibility', 'visible').show();
 


		$("div[id^=haiku-player]").each(function() {
		
			var num = this.id.match(/haiku-player(\d+)/)[1];
			var buttonId = "div#haiku-button" + num;
			var jpPlayTime = $("#jplayer_play_time" + num);
			var jpTotalTime = $("#jplayer_total_time" + num);
			var audioFile = $(buttonId + " a").attr("href");
			currentPlayer = 0;
			
			$(this).jPlayer({
				ready: function () {
					this.element.jPlayer("setFile", audioFile);
				},
				customCssIds: true,
				swfPath: jplayerswf,
				errorAlerts:false,
				nativeSupport:true
			})
			
			.jPlayer("onSoundComplete", function() {
//			stopPreviousPlayer();
//$(this).play(); 			
})
			
			// Slider
			$('#sliderPlayback' + num).slider({
				max: 100,
				range: 'min',
				animate: true,
				slide: function(event, ui) {
					$('#haiku-player' + num).jPlayer("playHead", ui.value*(100.0/global_lp));
					$(buttonId + " li.play").hide();
					$(buttonId + " li.pause").fadeIn(10);
				}
			});
		
			$(buttonId + " a.play").click(function() {
				stopPreviousPlayer();
				$(buttonId + " a img.listen").hide();
				$(buttonId + " li.play").hide();
				$("ul#controls" + num).fadeIn('fast');
				$("ul#info" + num).fadeIn('fast');
				$("div#haiku-player" + num).jPlayer("play");
				currentPlayer = num;
				return false;
			});	
		
			function stopPreviousPlayer() {
//alert('fine');
$("div#haiku-player1").jPlayer("play");
				
//$("div#haiku-player" + currentPlayer).jPlayer("stop");
//				showPauseBtn();
//			$("ul#controls" + currentPlayer).hide();	
//				$("ul#info" + currentPlayer).hide();	
//				$("div#haiku-button" + currentPlayer + " a img.listen").fadeIn('fast');
			}
			
			
		});
//	});	
});
 
